const db = wx.cloud.database()
const _ = db.command
// pages/searchpage/searchpage.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    value: '',
    placelist: wx.getStorageSync('placelist'),

    placeList: [],
    tjList: []
  },
  searchtap() {
    wx.showLoading({
      title: '正在加载',
    })
    var value = this.data.value
    this.gettjlist(value)
    this.getplacelist(value)
  },
  getData(e) {
    wx.showLoading({
      title: '正在加载',
    })
    console.log(e)
    var value = e.detail.value
    this.setData({
      value,
    })
    this.gettjlist(value)
    this.getplacelist(value)
  },
  gettjlist(value) {
    //获取团建表
    db.collection('tuanjianList').where(_.or([{
      name: db.RegExp({
        regexp: value,
        options: 'i',
      }),
      brief: db.RegExp({
        regexp: value,
        options: 'i',
      })
    }])).get().then(res => {
      console.log("团建信息", res)
      wx.hideLoading()
      this.setData({
        tjList: res.data.reverse()
      })
    })
  },
  getplacelist(value) {
    //获取景点
    db.collection('placeList').where(_.or([{
      name: db.RegExp({
        regexp: value,
        options: 'i',
      }),
      brief: db.RegExp({
        regexp: value,
        options: 'i',
      })
    }])).get().then(res => {
      console.log("景点信息", res)
      wx.hideLoading()
      this.setData({
        placeList: res.data.reverse()
      })
    })
  },
})